package com.jhgk.jhcee.expert.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.auth.mapper.SchoolRecruitMapper;
import com.jhgk.jhcee.auth.model.SchoolRecruit;
import com.jhgk.jhcee.auth.model.SchoolRecruitExample;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.expert.domain.dao.SchoolRecruitDao;
import com.jhgk.jhcee.expert.domain.model.SchoolRecruitMode;
import com.jhgk.jhcee.expert.service.SchoolRecruitService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/10 9:13.
 */
@Service(value = "SchoolRecruitServiceImpl")
public class SchoolRecruitServiceImpl implements SchoolRecruitService {

    @Autowired
    SchoolRecruitMapper schoolRecruitMapper;

    @Autowired
    SchoolRecruitDao schoolRecruitDao;

    @Override
    public PageResultful<PageInfo<SchoolRecruit>> searchSchoolRecruit(SchoolRecruitMode schoolRecruitMode) {
        if (null == schoolRecruitMode) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        SchoolRecruitExample example = new SchoolRecruitExample();
        SchoolRecruitExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceUuidEqualTo(schoolRecruitMode.getProvinceUuid());
        criteria.andYearEqualTo(schoolRecruitMode.getYear());
        PageHelper.startPage(schoolRecruitMode.getPage(), schoolRecruitMode.getLimit());
        List<SchoolRecruit> schoolRecruits = schoolRecruitMapper.selectByExample(example);
        if (schoolRecruits.isEmpty()) {
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        PageInfo<SchoolRecruit> pageInfo = new PageInfo<>(schoolRecruits);
        return PageResultful.success(pageInfo);
    }

    @Override
    public BasisResultful<Object> deleteSchoolRecruit(SchoolRecruit schoolRecruit) {
        return null;
    }

    @Override
    public BasisResultful<Object> updateBatchSchoolRecruit(List<SchoolRecruit> schoolRecruits) {
        return null;
    }

    @Override
    public BasisResultful<Object> addBatch(List<SchoolRecruit> schoolRecruits) {
        return null;
    }

    @Override
    public BasisResultful<Object> updateSchoolRecruit(String provinceUuid, Integer year) {
        if (null == year || StringUtils.isBlank(provinceUuid)) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        Integer updateStatus = schoolRecruitDao.updateSchoolRecruitMiniScoreSetNull(provinceUuid, year);
        if (updateStatus > 0) {
            return BasisResultful.success(BasisResultEnum.SUCCESS);
        }
        return BasisResultful.fail(BasisResultEnum.FAIL);
    }
}
